<?php

namespace Qwadmin\Controller;

class OrderController extends ComController {

    public function index(){
        if(!isset($_GET['status'])){
            $status = -1;
        }else{
            $status = I("status" , 0 , "intval");
            $map['status'] = $status ;
        }
        $page = I("p" , 1 , 'intval');
        $star_time = htmlspecialchars(I("star_time" , '') , ENT_NOQUOTES);
        $end_time = htmlspecialchars(I("end_time" , '') , ENT_NOQUOTES) ;
        $keyword = htmlspecialchars( I("q" , ''));
        
        if($star_time){
            $map['request_time'] = ['egt' , $star_time];
        }
        
        if($end_time){
            $map['request_time'] = ['elt' , $end_time];
        }
        
        if($keyword){
            $map['orderid'] = $keyword;
            $map['wechat_no'] = $keyword;
            $map['_logic'] = 'or';
        }
        
        $data = D("Order")->getList($page , $map);
        $this->assign("data" , $data) ;
        $this->assign("status" , $status);
        $this->assign("total_money" , D("Order")->totalMoney());
        $this->assign("count_order" , D("Order")->countOrder());
        $this->assign("empty" , "<tr><td colspan='7' class='text-center'>暂无任何订单信息</td></tr>");
        $this->display();
    }
    
    public function income() {
        $date = I("date", 0, 'intval');
        $start_date = htmlspecialchars(I("start_date", ''), ENT_NOQUOTES);
        $end_date = htmlspecialchars(I("end_date", ''), ENT_NOQUOTES);

        $map["account"] = 1; //只显示未扣量的订单
        if (!empty($start_date)) {
            //检查日期是否有效
            list($y, $m, $d) = explode('-', $start_date);
            if (checkdate($m, $d, $y)) {
                $map["create_time"] = array(array('EGT', strtotime($start_date)));
            } else {
                $start_date = '';
            }
        }
        if (!empty($end_date)) {
            //检查日期是否有效
            list($y, $m, $d) = explode('-', $end_date);
            if (checkdate($m, $d, $y)) {
                $map["create_time"][] = array('LT', strtotime($end_date));
            } else {
                $end_date = '';
            }
        }
        //默认查询当前的数据
        if (empty($start_date) && empty($end_date)) {
            $start_date = date('Y-m-d', time());
            $end_date = date('Y-m-d', strtotime("+1 day"));
            $map["create_time"] = array(array('EGT', strtotime($start_date)));
            $map["create_time"][] = array('LT', strtotime($end_date));
        }


        $list = D("Income")->getList($map);
        $this->data = $list;
        //获取用户的锁定会员及其提现权限
        $this->assign('UserJurisdiction', D("member")->getUserJurisdiction(session('uid')));
        $this->assign("start_date", $start_date);
        $this->assign("end_date", $end_date);
        $this->display();
    }

}
